/*
 * 
 * LegendShop 多用户商城系统
 * 
 *  版权所有,并保留所有权利。
 * 
 */
package com.legendshop.oa.tag;

import com.legendshop.oa.constants.CommonConfigPropertiesEnum;
import com.legendshop.oa.constants.GlobalConfigPropertiesEnum;
import com.legendshop.util.AppUtils;
import com.legendshop.util.EnvironmentConfig;
import com.legendshop.util.SystemUtil;

/**
 * 计算图片路径等
 */
public class ResourcePathUtil {

	/** The Constant BIG_IMAGE. */
	public static final String BIG_IMAGE = "bigImage";

	public static final String SNAPSHOT_BIG_IMAGE = "snapBigImage";

	/** The Constant BACKUP_IMAGE. */
	public static final String BACKUP_IMAGE = "backupImage";

	/** The Constant SMALL_IMAGE. */
	public static final String SMALL_IMAGE = "smallImage";

	public static final String HTML_COMMON = "html/";

	public static final String DOWNLOAD_PATH = "WEB-INF/download";

	// 大图片
	/**
	 * Gets the big files absolute path.
	 * 
	 * @return the big files absolute path
	 */
	public static String getBigFilesAbsolutePath() {
		String bigImagePath = EnvironmentConfig.getInstance().getPropertyValue(CommonConfigPropertiesEnum.BIG_PIC_PATH);
		if (AppUtils.isBlank(bigImagePath)) {
			bigImagePath = SystemUtil.getSystemRealPath() + BIG_IMAGE;
		}
		return bigImagePath;
	}

	/**
	 * 商品快照 大图路径
	 * 
	 * @return
	 */
	public static String getSnapshotBigFilesAbsolutePath() {
		String bigImagePath = EnvironmentConfig.getInstance().getPropertyValue(CommonConfigPropertiesEnum.SNAPSHOT_BIG_PIC_PATH);
		if (AppUtils.isBlank(bigImagePath)) {
			bigImagePath = SystemUtil.getSystemRealPath() + SNAPSHOT_BIG_IMAGE;
		}
		return bigImagePath;
	}

	/**
	 * 获取小图片的绝对路径
	 * 
	 * @return the small files absolute path
	 */
	public static String getSmallFilesAbsolutePath() {
		String smallImagePath = EnvironmentConfig.getInstance().getPropertyValue(CommonConfigPropertiesEnum.SMALL_PIC_PATH);
		if (AppUtils.isBlank(smallImagePath)) {
			smallImagePath = SystemUtil.getSystemRealPath() + SMALL_IMAGE;
		}
		return smallImagePath;
	}

	/**
	 * 获取图片备份路径
	 * 
	 * @return the backup files absolute path
	 */
	public static String getBackupFilesAbsolutePath() {
		String backupImagePath = EnvironmentConfig.getInstance().getPropertyValue(CommonConfigPropertiesEnum.BACKUP_PIC_PATH);
		if (AppUtils.isBlank(backupImagePath)) {
			backupImagePath = SystemUtil.getSystemRealPath() + BACKUP_IMAGE;
		}
		return backupImagePath;
	}


	/**
	 * 获取缩略图的前缀.
	 * 
	 * @return the user files path servlet
	 */
	public static String getSmallImagePathPrefix() {
		return EnvironmentConfig.getInstance().getPropertyValue(GlobalConfigPropertiesEnum.IMAGES_PATH_PREFIX);
	}

	// 读取的大图片路径
	public static String getPhotoPathPrefix() {
		return EnvironmentConfig.getInstance().getPropertyValue(GlobalConfigPropertiesEnum.PHOTO_PATH_PREFIX);
	}

	public static String getSnapPhotoPathPrefix() {
		return EnvironmentConfig.getInstance().getPropertyValue(GlobalConfigPropertiesEnum.SNAP_PHOTO_PATH_PREFIX);
	}

	/**
	 * 读取图片服务器的地址 如果没有配置，则采用系统contextPath
	 * 
	 * @return
	 */
	public static String getInnerPhotoServer() {
		String photoServerPath = EnvironmentConfig.getInstance().getPropertyValue(CommonConfigPropertiesEnum.INNER_PHOTO_SERVER);
		if (AppUtils.isBlank(photoServerPath)) {
			photoServerPath = SystemUtil.getContextPath();
		}
		return photoServerPath;
	}

	/**
	 * 读取图片服务器的地址 如果没有配置，则采用系统contextPath
	 * 
	 * @return
	 */
	public static String getPhotoServer() {
		String photoServerPath = EnvironmentConfig.getInstance().getPropertyValue(CommonConfigPropertiesEnum.PHOTO_SERVER);
		if (AppUtils.isBlank(photoServerPath)) {
			photoServerPath = SystemUtil.getContextPath();
		}
		return photoServerPath;
	}

	public static String getResourceVersion() {
		String resourceVersion = EnvironmentConfig.getInstance().getPropertyValue(CommonConfigPropertiesEnum.RESOURCE_VERSION);
		if (AppUtils.isBlank(resourceVersion)) {
			resourceVersion = "1";
		}
		return resourceVersion;
	}

	/**
	 * 邮件模板文件路径
	 * 
	 * @return
	 */
	public static String getMailHtmlPath() {
		String downloadPath = SystemUtil.getSystemRealPath() + DOWNLOAD_PATH;
		return downloadPath;
	}

	public static String getOSSDomainName() {
		String ossDomainName = EnvironmentConfig.getInstance().getPropertyValue(CommonConfigPropertiesEnum.OSS_DOMAIN_NAME);
		return ossDomainName;
	}

}
